#define __STDC_WANT_LIS_EXT1__ 1
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

int main (void){
  char delimiters[]=" \".,;:!?)(";
  char buf[100];
  char str[1000];
  char *ptr=NULL;
  str[0]='\0';
  size_t str_len=sizeof(str);
  size_t buf_len=sizeof(buf);
  printf("Enter some prose that is less than %zd characters.\n"
           "Terminate input by entering an empty line:\n",str_len);
  while(true){
    if(!gets(buf,buf_len)){
      printf("Error reading string.\n");
      return 1;
    }
    if(!strlen(buf)){
      break;
    }
    if(strcat(str,buf)){
      printf("Maximum permitted input length exceeded.\n");
      return 1;
    }
  }
  printf("The words in the prose that you entered are:\n",str);
  unsigned int word_count =0;
  char *pWord=strtok(str,delimiters);
  if(pWord){
    do{
      printf("%-18s",pWord);
      if(++word_count % 5==0){
      printf("\n");
      }
      pWord=strtok(NULL,delimiters);
    }while(pWord);
    printf("\n%u words found.\n",word_count);
  }else{
     printf("No words found.\n");
  }
  return 0;
}
